﻿<%@ Page Language="vb" AutoEventWireup="false" Codebehind="SetSubMedia.aspx.vb" Inherits="Slxt.SetSubMedia" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="mwc" Namespace="MySoft.WebControls" Assembly="MySoft.WebControls" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>媒体子类</title>
	<!-- Global -->
	<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
	<script language="javascript" src="/_common/scripts/global.js"></script>
	<!-- Menu -->
	<link rel="stylesheet" type="text/css" href="/_nav/menu.css">
	<script language="javascript" src="/_nav/menu.js"></script>
	<!-- Grid -->
	<link rel="stylesheet" type="text/css" href="/_grid/map_grid.css">
	<!-- Repeater -->
	<script language="javascript" src="/_grid/rep_grid.js"></script>
	<!-- Utility-->
	<script language="javascript" src="/_controls/util/util.js"></script>
    <!-- DropDownTree -->
    <link href="/_controls/tree/dropdowntree.css" type="text/css" rel="stylesheet">
    <link href="/pubproject/_controls/CRMControls/ProjDDTree.css" type="text/css" rel="stylesheet">
    <!-- GridTree -->
    <link href="/_controls/tree/gridtree.css" type="text/css" rel="stylesheet">

    <script language="javascript" src="/_common/scripts/global.js"></script>

    <script language="javascript" src="/_controls/settings.aspx"></script>

    <script language="javascript" src="/_controls/util/util.js"></script>

    <script language="javascript" src="/_forms/FormBase.js"></script>
	<!-- Public -->
	<script language="javascript" src="/Slxt/JS/Public.js"></script> 
	<link rel="stylesheet" type="text/css" href="/_controls/tree/tree.css" />
	<script language="javascript">
	    //在线帮助文件
	    var _MyHelpfile = "";
	    var oid;

	    //窗体加载
	    window.onload = function() {
	        initRepeater(tblSubMedia);
	    }

	    //初始化
	    function initRepeater(tblList) {
	        initGrid(tblList);
	        // 获取表头设置样式
	        var head = tblHeader.rows[0];
	        head.id = "trHeader";
	        head.setAttribute("align", "center");

	        var cell;
	        for (var i = 0, j = head.cells.length; i < j; i++) {
	            cell = head.cells[i];
	            cell.className = "gridBar";
	            cell.style.background = "#E9E7D7 url(/_imgs/bar_line.gif) no-repeat right"
	            cell.innerHTML = "<nobr>" + cell.innerHTML + "</nobr>"
	        }
	        // 设置浮动表头
	        var string = '<table width="100%" cellpadding="0"  cellspacing="0" border="0" style="table-layout:fixed;position:absolute; top:expression(this.offsetParent.scrollTop)">' + head.outerHTML + '</table>'
	        tblHeader.parentNode.insertAdjacentHTML("afterBegin", string);
	    }
        
	    // 打开新增窗口
	    function openAddWin() {
	        //若主页面没有选中媒体大类，则弹出“只能在一个媒体大类下新增媒体子类！”
	        //取选中行，数组
	        var a = getSelectedTr("tblSubMedia");
	        if (!a) {
	            alert("只能在一个媒体大类下新增媒体子类！");
	            return;
	        }
	        var o = document.all("tblSubMedia");
	        if (o.rows.length == 0) {
	            alert("请先增加媒体大类");
	            return;
	        }

	        if (a[0].value.lastIndexOf(".") >= 0) {
	            alert("只能在一个媒体大类下新增媒体子类！");
	            return;
	        }
            
            //传GUID、code和name
	        var arrAddList = [];
	        arrAddList.push(a[0].oid);
	        arrAddList.push(a[0].value);
	        arrAddList.push(a[0].text);

	        var sFile = "/Slxt/XMZB/SetSubMedia_Edit.aspx?mode=1&param=" + arrAddList.join("|") + "&oid=";
	        openMyWin(sFile, "", 550, 180);
	    }

	    // 打开修改窗口
	    function openModiWin() {
	        var a = getSelectedTr("tblSubMedia");
	        //选中的不是媒体子类则不能修改
	        if (a[0].value.lastIndexOf(".") < 0) {
	            return;
	        }

	        //传GUID、code和name
	        var arrAddList = [];
	        arrAddList.push(a[0].MainGUID);
	        arrAddList.push(a[0].MainCode);
	        arrAddList.push(a[0].MainName);

	        var sFile = "/Slxt/XMZB/SetSubMedia_Edit.aspx?mode=2&param=" + arrAddList.join("|") + "&oid=" + a[0].oid;
	        openMyWin(sFile, "", 550, 180);
	    }

	    //删除
	    function openDelWin() {
	        //遍历checkBox 多选情况
	        var iMainChecked = 0, iSubChecked = 0;
	        var delSubMediaGUID = [];
	        var obj = document.all("chkBld");
	        for (i = 0; i < obj.length; i++) {
	            if (obj[i].checked == true) {
	                if (obj[i].code.lastIndexOf(".") == 3) {
	                    iMainChecked++;
	                } else {
	                    iSubChecked++;
	                }
	                delSubMediaGUID.push(obj[i].oid);
	            }
	        }
	        //若没有选择媒体子类，提示“请选择要删除的媒体子类！”，不执行后续操作。
	        if (iSubChecked == 0) {
	            alert("请选择要删除的媒体子类！");
	            return;
	        }
	        //若选项中包含媒体大类，提示“只能删除媒体子类！”，不执行后续操作
	        if (iMainChecked > 0) {
	            alert("只能删除媒体子类！");
	            return;
	        }

	        if (confirm("确实要删除选择的记录吗？")) {
	            var strFile = "/Slxt/XMZB/SetSubMedia_XMLHTTP.aspx";
	            var strReturn = openXMLHTTP(strFile, "DelSubMeida", delSubMediaGUID.join(","));
	            if (strReturn != "success") {
	                alert(strReturn);
	            }
	        }else {
	            return;
	        }
	        
	        window.location.href = window.location.href;
	    }

	    function ValidOperate(type) {
	        //遍历checkBox 多选情况
	        var iMainChecked = 0, iSubChecked = 0;
	        var opSubMediaGUID = [];
	        var obj = document.all("chkBld");
	        for (i = 0; i < obj.length; i++) {
	            if (obj[i].checked == true) {
	                if (obj[i].code.lastIndexOf(".") == 3) {
	                    iMainChecked++;
	                } else {
	                    iSubChecked++;
	                }
	                opSubMediaGUID.push(obj[i].oid);
	            }
	        }
	        //若没有选择媒体子类，提示“请选择要设置的媒体子类！”，不执行后续操作。
	        if (iSubChecked == 0) {
	            alert("请选择要设置的媒体子类！");
	            return;
	        }
	        //若选项中包含媒体大类，提示“只能针对媒体子类设置！”，不执行后续操作。
	        if (iMainChecked > 0) {
	            alert("只能针对媒体子类设置！");
	            return;
	        }

	        var strFile = "/Slxt/XMZB/SetSubMedia_XMLHTTP.aspx?valid=" +type;
	        var strReturn = openXMLHTTP(strFile, "ValidOperate", opSubMediaGUID.join(","));
	        if (strReturn != "success") {
	            alert(strReturn);
	        }

	        window.location.href = window.location.href;
	    }


	    //选择节点
	    function selectNode(o) {
	        //选中行
	        SelectCharindex(o.parentElement.parentElement.parentElement.code, o.checked);
	    }

	    function selectCurRow(tr) {
	        var chk;
	        if (event.srcElement.tagName === "INPUT") {
	            chk = event.srcElement;
	        } else {
	            chk = tr.getElementsByTagName("INPUT")[0];
	            if (chk.checked == true) {
	                chk.checked = false;
	            } else {
	                chk.checked = true;
	            }
	        }
	        //选中行
	        SelectCharindex(tr.code, chk.checked);
	    }

	    // 选中子节点
	    function SelectCharindex(sCode, bCheck) {
	        var strCode;
	        var j;
	        for (var i = 0; i < tblSubMedia.rows.length; i++) {
	            strCode = tblSubMedia.rows[i].code + ".";
	            j = strCode.indexOf(sCode + ".");
	            if (j >= 0) {
	                tblSubMedia.rows[i].cells[0].children[2].children[0].checked = bCheck;
	            }
	        }

	        //selectParentCheck(sCode);
	    }

	    // 反向选中父节点
	    function selectParentCheck(sCode) {
	        var sParentCode, strCode;
	        // 子节点存在父级时
	        if (sCode.lastIndexOf(".") >= 0) {
	            // 表示子节点的所有兄弟节点是否全部选中
	            var blnFlg = false;         
	            // 获取父节点CODE
	            sParentCode = sCode.substring(0, sCode.lastIndexOf("."));
	            for (var i = 0; i < tblSubMedia.rows.length; i++) {
	                strCode = tblSubMedia.rows[i].code;
	                // 当前节点CODE为父级节点CODE 且 当前节点未选中，则表示该父节点的子节点未全部选中，即该父节点不选中
	                // 否则该父节点选中
	                if (strCode.substring(0, strCode.lastIndexOf(".")) == sParentCode) {
	                    if (!tblSubMedia.rows[i].cells[0].children[2].children[0].checked) {
	                        blnFlg = false;
	                        break;
	                    } else {
	                        blnFlg = true;
	                    }
	                }
	            }
	            // 遍历所有节点的CHECKBOX，选中上一步子节点和其兄弟节点全部选中的父节点
	            // 没有父节点是跳数
	            var obj = document.all("chkBld");
	            for (i = 0; i < obj.length; i++) {
	                if (obj[i].code == sParentCode) {
	                    obj[i].checked = blnFlg;
	                    if (selectParentCheck(sParentCode))
	                        return true;
	                }
	            }
	        }
	        return false;
	    }
	    
	    
	    
	</script>
  </head>
<body MS_POSITIONING="GridLayout">
	<form id="Form1" runat="server" method="post">
		<table style="FONT-SIZE: 9pt" height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
			<tr height="1">
				<td>
				  <mnu:AppGridMenu id="appGridMenu" runat="server" />
				</td>
			</tr>
			<tr>
				<td vAlign="top" style="background-color:white">
				    <%--Repeater开始--%>
				    <div style=" position:relative; height:100%; overflow:auto">
				    <table id="tblHeader" style="table-layout:fixed"  width="100%" cellpadding="0" cellspacing="0">
				        <tr style="cursor: hand;">
				            <td width="320px">
				                媒体类别
				            </td>
				            <td width="200px">
				                编码
				            </td>
				            <td width="150px">
				                当前状态
				            </td>
				            <td>
				                近三月无投放
				            </td>
				        </tr>
				        <tr>
				            <td colspan="4">
				                <table id="tblSubMedia"  width="100%" style="table-layout:fixed" MultiSelect="false"  cellpadding="0" cellspacing="0" border="0"  gridID="myRep" onclick="handleClick();"  ondblclick="openModiWin();" class="singleSelectTree" defaultShowLevel="3">
                               
                                <mwc:Repeater ID="repSM" runat="server" SortSignDESC='<img src="/_imgs/ico_arrow_d.gif">' SortSignASC='<img src="/_imgs/ico_arrow_u.gif">' PKField="HsCostGUID" EnablePager="false">
                                    <ItemTemplate>
                                        <tr height="24" oid='<%# DataBinder.Eval(Container.DataItem,"MediaGUID")%>'  
                                            code='<%# DataBinder.Eval(Container, "DataItem.HierarchyCode") %>' 
                                            value='<%# DataBinder.Eval(Container, "DataItem.MediaCode") %>' 
                                            text='<%# DataBinder.Eval(Container, "DataItem.MediaName") %>'
                                            MainGUID='<%# DataBinder.Eval(Container, "DataItem.MainGUID") %>' 
                                            MainCode='<%# DataBinder.Eval(Container, "DataItem.MainCode") %>' 
                                            MainName='<%# DataBinder.Eval(Container, "DataItem.MainName") %>' 
                                            allowselect='0' 
                                            is_hide="false"
                                            onclick="tblSubMedia.clickNode(this);">                                            
                                            
                                            <td class="gridBorder" align="left" width="320px">
                                                <span></span><label style="cursor: hand"></label>
                                                <span title="<%#DataBinder.Eval(Container.DataItem, "MediaName")%>">
                                                        <input type="checkbox" name="chkBld" onclick="selectNode(this)" code='<%# DataBinder.Eval(Container, "DataItem.HierarchyCode") %>' oid='<%# DataBinder.Eval(Container.DataItem,"MediaGUID")%>'>
                                                    <span><%#DataBinder.Eval(Container, "DataItem.MediaName")%></span>
                                                </span>
                                                
                                            </td>
                                            <td class="gridBorder" align="left" width="200px">
                                                <nobr title="<%#DataBinder.Eval(Container.DataItem, "MediaCode")%>">
                                                    <%#DataBinder.Eval(Container.DataItem, "MediaCode")%>
                                                </nobr>                                            
                                            </td>
                                            <td class="gridBorder" align="center" width="150px">
                                                <nobr title="<%#DataBinder.Eval(Container.DataItem, "STATE")%>">
                                                    <%#DataBinder.Eval(Container.DataItem, "STATE")%>
                                                </nobr>
                                            </td>
                                            <td class="gridBorder" align="center">
                                                <nobr title="<%#DataBinder.Eval(Container.DataItem, "NoneActive")%>">
                                                    <%#DataBinder.Eval(Container.DataItem, "NoneActive")%>
                                                </nobr>
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                </mwc:Repeater>
                        </table>
				            </td>
				        </tr>
				    </table>
				        
                    </div>
                </td>
			</tr>
		</table>
	</form>
</body>
</html>